<template>
  <div class="home-icons">
    <swiper>
      <swiper-slide v-for="(page, index) of pages" :key="index">
        <div class="icon" v-for="item in page" :key="item.id"> 
          <img :src="item.iconUrl" alt="">
          <p class="desc">{{ item.iconDesc }}</p>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script>

export default {
  name: 'HomeIcons',
  data () {
    return {
      iconList:[{
        id: '001',
        iconUrl: 'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
        iconDesc: '景点门票多少钱啊'
      },{
        id: '002',
        iconUrl: 'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
        iconDesc: '景点门票'
      },{
        id: '003',
        iconUrl: 'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
        iconDesc: '景点门票'
      },{
        id: '004',
        iconUrl: 'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
        iconDesc: '景点门票'
      },{
        id: '005',
        iconUrl: 'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
        iconDesc: '景点门票'
      },{
        id: '006',
        iconUrl: 'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
        iconDesc: '景点门票'
      }]
    }
  },
  computed: {
    pages () {
      const pages = []
      this.iconList.forEach((item, index) => {
        const page = Math.floor(index/4)
        if(!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
  .home-icons
    width: 100%
    height: 25vw
    // border-bottom: 0.01rem solid grey 
    // background: green
    .pics
      width: 100%
      height: 25vw
      background: blue
      .title
        font-size: .35rem
        font-weight: bold
        left: 0
        display: inline-block
      .pic-wrapper
        width: 100%
    .icon
      float: left 
      width: 25%
      height: 25vw
      border-right: 0.01rem solid rgba(7, 17, 27, 0.1)
      text-align: center
      box-sizing: border-box
      img
        width: 60%
        height: 60%
        margin-top: .25rem
      .desc
        overflow:hidden
        white-space: nowrap
        text-overflow: ellipsis
</style>
